package cn.sypt.yuhao.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import cn.itcast.servlet.BaseServlet;
import cn.sypt.yuhao.dao.ChartsDao;
import cn.sypt.yuhao.domain.Charts;
import cn.sypt.yuhao.domain.User;
import cn.sypt.yuhao.model.Tool;

public class ChartsServlet extends BaseServlet {
private ChartsDao cd=new ChartsDao();

	public String findByCharts(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		List<Charts> listCharts=cd.findBy();
	
		JSONArray jsonarray=JSONArray.fromObject(listCharts);
		response.getWriter().print(jsonarray);
		System.out.println(jsonarray);
		request.setAttribute("listchar",jsonarray);
		return "f:/admin/charts.jsp";
	}
	public String findBySC(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		User user=(User) request.getSession().getAttribute("user");
		String uid=user.getUid();
		////收藏实验可视化分析
		List<Charts> listCharts=cd.findBySC(uid);
	//	String msg1=Tool.getTip(listCharts);
		JSONArray jsonarray=JSONArray.fromObject(listCharts);
		request.setAttribute("listchar",jsonarray);
	//	request.setAttribute("msg1", msg1);
		/////////下载实验可视化分析
		List<Charts> listCharts1=cd.findByXZ(uid);
	//	String msg2=Tool.getTip(listCharts1);
		JSONArray jsonarray1=JSONArray.fromObject(listCharts1);
		request.setAttribute("listchar1",jsonarray1);
	//	request.setAttribute("msg2", msg2);
		////评论实验可视化分析
		List<Charts> listCharts2=cd.findByPL(uid);
		
		JSONArray jsonarray2=JSONArray.fromObject(listCharts2);
		request.setAttribute("listchar2",jsonarray2);
		if(!listCharts2.isEmpty()){
			
			String msg3=Tool.getTip(listCharts2);
			request.setAttribute("msg3", msg3);
		}
		return "f:/home/chart.jsp";
	}
}
